<template>
	<view class="content">
		<view style="padding: 5px 10px 10px 10px;">
			<u-skeleton rows="4" :loading="hotGoodsLoading">
				<view v-for="(item,index) in collectGoods" :key="index">
					<view class="card" @click="toDetails(item.id)">
						<view>
							<image style="width: 100px; height: 100px;border-radius: 8px;" :src="item.image">
							</image>
						</view>
						<view style="margin-left: 10px;">
							<text class="grid-text_goods">{{item.goodsName}}</text>
							<view style="padding: 10px 0 10px 0;display: flex;">
								<text style="font-size: 11px;margin-top: 1px; color: #DC143C;">已售：</text><text
									class="text_common">{{item.sale}}</text>
								<u-icon class="icon_common" name="eye" color="#67C23A"></u-icon><text
									class="text_common">{{item.browse}}</text>
								<u-icon class="icon_common" name="star" color="#E6A23C"></u-icon><text
									class="text_common">{{item.collectNum}}</text>
								<u-icon class="icon_common" name="chat" color="#409EFF"></u-icon><text
									class="text_common">{{item.commentNum}}</text>
							</view>
							<view style="display: flex;">
								<u-icon class="text" size="20" name="rmb" color="#DC143C"></u-icon><text
									style="color: #DC143C; font-size: 17px;font-weight: bold;">{{item.price}}</text>
							</view>
						</view>
					</view>
				</view>
			</u-skeleton>
		</view>

		<!-- 空状态 -->
		<view v-if="isEmpty">
			<u-empty mode="favor" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
	} from '@dcloudio/uni-app';
	import {
		ref
	} from 'vue';
	import {
		getUserInfo
	} from "@/stores/index.js";
	import {
		queryCollectGoods
	} from "@/api/collectgoods/index.js";

	const user = getUserInfo();
	const hotGoodsLoading = ref(true);
	const isEmpty = ref(false);
	onLoad(() => {
		getCollectGoodsData();
	});

	//获取当前用户的收藏商品数据
	const collectGoods = ref([]);
	const getCollectGoodsData = () => {
		queryCollectGoods(user.id).then((res) => {
			if (res.code === 200 && res.data !== null) {
				collectGoods.value = res.data;
				hotGoodsLoading.value = false;
			} else {
				isEmpty.value = true;
				hotGoodsLoading.value = false;
			}
		})
	}

	//跳往商品详情页
	const toDetails = (goodsId) => {
		uni.navigateTo({
			url: "/pages/detail/detail?goodsId=" + goodsId
		})
	}
</script>

<style scoped lang="scss">
	.content {
		background-color: #fff;
	}

	.card {
		display: flex;
		margin-top: 15px;
		padding: 5px;
		width: 100%;
		height: 120px;
		background-color: #F5F7FA;
		border-radius: 10px;
		box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
	}

	.card:active {
		background-color: #fff;
		opacity: 1;
	}

	.grid-text_goods {
		font-size: 15px;
		color: #303133;
		font-weight: 600;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		font-family: "华文楷体";
	}

	.text_common {
		color: #909399;
		font-size: 13px;
		margin-right: 15px;
	}
</style>